package newKe;

import java.util.ArrayList;
import java.util.List;

public class NC45 {
    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }

    public int[][] threeOrders (TreeNode root) {
        // write code here
        List<Integer> res1 = new ArrayList<>();
        List<Integer> res2 = new ArrayList<>();
        List<Integer> res3 = new ArrayList<>();

        pre(root,res1);
        in(root,res2);
        next(root,res3);

        int[][] mat = new int[3][];

//        Integer[] integers = res1.toArray(new Integer[0]);
        int[] ints = res1.stream().mapToInt(i -> i).toArray();
        int[] ints1 = res2.stream().mapToInt(i -> i).toArray();
        int[] ints2 = res3.stream().mapToInt(i -> i).toArray();
        mat[0] = ints;
        mat[1] = ints1;
        mat[2] = ints2;

        return mat;
    }

    public void pre(TreeNode root,List<Integer> res){
        if (root == null) {
            return;
        }
        res.add(root.val);
        pre(root.left, res);
        pre(root.right, res);
    }

    public void in(TreeNode root,List<Integer> res){
        if (root == null) {
            return;
        }

        in(root.left, res);
        res.add(root.val);
        in(root.right, res);
    }

    public void next(TreeNode root,List<Integer> res){
        if (root == null) {
            return;
        }
        next(root.left, res);
        next(root.right, res);
        res.add(root.val);
    }
}
